<% set_page_title(:project_all_issues_labels, project_name: current_project.name) %>

<%= turbo_frame_tag 'issue_label_form', src: (params[:open_form] ? params[:form_issue_label_id] ? edit_project_issue_label_path(current_project, params[:form_issue_label_id]) : new_project_issue_label_path(current_project) : nil) do %>
<% end %>

<%= turbo_frame_tag 'issue_label_removal_confirmation' do %>
<% end %>

<%= render partial: 'projects/navigation_header', locals: {
  project: current_project,
  header_width: true,
  sub_section: {
    title: IssueLabel.model_name.human,
    icon: :issue_labels
  }
} %>

<div class="px-8 grow w-full w-header mx-auto">
  <%= turbo_frame_tag 'issue_labels', autoscroll: true, 'data-autoblock-scroll': 'start' do %>
    <div class="flex flex-col gap-4 lg:gap-8 flex-wrap justify-stretch">

      <div class="card">
        <div class="card-body bg-base-100 border-base-300 rounded-box">

          <%= render partial: 'filter', locals: { q: @q } %>

          <div class="flex justify-end mb-2 mt-8">
            <%= link_to new_project_issue_label_path(current_project), class: "btn-primary btn-sm btn", data: { turbo_frame: 'issue_label_form' } do %>
              <%= icon_for(:add_entry) %>
              <%= "#{t('actions.create')} #{IssueLabel.model_name.human.downcase}" %>
            <% end %>
          </div>
          <% if @issue_labels.count.zero? %>
            <%= render EmptyListComponent.new(
              message: (
                params[:q].present? ?
                  t("zero_records_for_this_search", resource_name: IssueLabel.model_name.human) :
                  t("zero_records", resource_name: IssueLabel.model_name.human)
              ),
              action: {
                url: new_project_issue_label_path(current_project),
                text: t('click_here_to_create_one'),
                extra_options: { data: { turbo_frame: 'issue_label_form' } }
              })
            %>
          <% else %>
            <table class="table table-header table-sm">
              <thead>
                <tr>
                  <th style="width: 60%"><%= sort_link(@q, :title, IssueLabel.model_name.human) %></th>
                  <th style="width: 20%"><%= sort_link(@q, :updated_at, IssueLabel.human_attribute_name(:updated_at)) %></th>
                  <th style="width: 20%"><%= t(:actions, scope: :menu) %></th>
                </tr>
              </thead>
              <tbody id='issue-labels-list'>
                <%= render partial: 'issue_label', collection: @issue_labels, as: :issue_label %>
              </tbody>
            </table>
            <%== pagy_summary(@pagy) %>
          <% end %>
        </div>
      </div>

    </div>
  <% end %>
</div>